package com.ty.day6;

import java.util.Arrays;
import java.util.Random;

/**
 * Created by IntelliJ IDEA.
 * Author : txy
 * Create 2023/11/2 15:29
 */
public class Three {
    public static void main(String[] args) {
        int n = 3;
        int[][] a = new int[n][n];
        Random random = new Random();
        int sum = 0;
        System.out.println(n + "阶矩阵为：");
        for (int i = 0; i < a.length; i++) {
            for (int j = 0; j < a[i].length; j++) {
                a[i][j] = random.nextInt(100) + 1;
                System.out.print(a[i][j] + " ");
                if (i == j) {
                    sum = sum + a[i][j];
                }
            }
            System.out.println();
        }
        System.out.println(n + "阶矩阵的对角线之和为：" + sum);
    }
}
